<?php

class MobileDashboardController extends MobileController {

	/*
	|--------------------------------------------------------------------------
	| Default Home Controller
	|--------------------------------------------------------------------------
	|
	| You may wish to use controllers instead of, or in addition to, Closure
	| based routes. That's great! Here is an example controller method to
	| get you started. To route to this controller, just add the route:
	|
	|	Route::get('/', 'HomeController@showWelcome');
	|
	*/
    private $orderService = null;

	public function getIndex($token=null, $user=null, $auth=null)
	{
        $input['order'] = 'updated_at';
        $result =  $this->getService()->getList($input, 6);
        $entries = $result['entries'];

        $input['is_top'] = 1;
        $result =  $this->getService()->getList($input, 6);
        $top_entries = $result['entries'];

        $order = $this->getOrderService()->getLastOrder($this->member->id);

        return View::make(self::$view_path.'.dashboard', compact('entries','top_entries', 'order', 'user', 'auth'));
	}

    private function getService() {
        if(is_null($this->service)){
            $this->service = new MobileFoodService();
        }
        return $this->service;
    }

    private function getOrderService() {
        if(is_null($this->orderService)){
            $this->orderService = new MobileOrderService();
        }
        return $this->orderService;
    }
}
